package com.sport.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable{
    //响应码
    private Integer code;
    //响应信息
    private String message;
    //响应数据
    private T data;

    public Result(int code, String message,T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }
    public Result(String message,T data) {
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> success(){
        return new Result<>(200,"成功！");
    }
    public static <T> Result<T> success(String message){
        return new Result<>(200,message);
    }
    public static <T> Result<T> success(T data){
        return new Result<>(200,"成功！",data);
    }
    public static <T> Result<T> success(String message,T data){
        return new Result<>(200,message,data);
    }
    public static <T> Result<T> error(){
        return new Result<>(500,"失败！");
    }
    public static <T> Result<T> error(String message){
        return new Result<>(500,message);
    }
    public static <T> Result<T> error(int code,String message){
        return new Result<>(code,message);
    }

    public static <T> Result<T> error( int code,String message,T data){
        return new Result<>(code,message,data);
    }
}
